function funType(sn: string | null): string{
    if(sn === null){
        return 'null'
    } else {
        return sn
    }
}
// #或者 使用运算符
function funType2(sn: string | null): string{
    return sn || 'null'
}

// typeof
const StudentId = (data: number | string | undefined ) => {
    if(typeof data === "string"){
        console.log(`我是字符串:${data}`)
    }

    if(typeof data === "number"){
        console.log(`我是数字:${data}`)
    }

    if(typeof data === "undefined"){
        console.log(data)
    }
    if(typeof data !== "object"){
        console.log('我不是object')
    }
}
StudentId('pengyuyan') // 我是字符串:pengyuyan
StudentId(100) // 我是数字:100
StudentId(undefined) // undefined

// instanceof
class NumberObj{
    count: number = 1
}
class NumberSecondObj{
    count: number = 1
}
function addSecond (first : object | NumberObj, second: object | NumberSecondObj){
    if(first instanceof NumberObj && second instanceof NumberSecondObj){
        return first.count + second.count
    }
    return 0
}
console.log(addSecond(new NumberObj(),new NumberSecondObj()))  // 2

// in 语法
interface Bird {
    fly: boolean;
    sing: () => {};
}
interface Dog {
    fly: boolean;
    bark: () => {};
}
function trainAnimalSecond(animal: Bird | Dog){
    if('sing' in animal){
        animal.sing()
    }else {
        animal.bark()
    }
}
console.log({fly:true,sing:() => {}})
